<?php
//include_once "log4php/Logger.php";
include_once dirname(__FILE__).DIRECTORY_SEPARATOR."../DAO/mysqllib.php";

require_once "Transaction.php";

class BaseContext {
	private $logger;
	private $transaction;

	function __construct() {
		$this->transaction = new Transaction();
	}

	function cloneEnv(BaseContext $context2) {
		$this->transaction = $context2->getDBTransaction();
		return $this;
	}

	function logInfo($code, $message) {
		try {
			$this->logger->info($this->getLogPrefix().$code . " - " . $message);
			return true;
		} catch (Exception $e) {
			echo $e->getMessage();
		}
	}

	function logError($code, $message) {
		try {
			$this->logger->error($this->getLogPrefix().$code . " - " . $message);
			return true;
		} catch (Exception $e) {
		}
	}

	function logDebug($code, $message) {
		try {
			$caller = debug_backtrace();
			$this->logger->debug($caller[1]['file'].$this->getLogPrefix().debug_backtrace().$code . " - " . $message);
			return true;
		} catch (Exception $e) {
		}
	}

	/**
	 * log to database. no implementation yet.
	 * @param String $code
	 * @param String $message
	 */
	function logAudit($code, $message) {

	}

	/**
	 * Enter description here ...
	 * @param Exception $exception
	 */
	function logException($exception) {
		//TODO: log exception as error
		$this->logError($exception->getCode(), $exception->getMessage());
	}

	/**
	 * return the prefix for different level of logging
	 * return String
	 */
	protected function getLogPrefix() {
		return "";
	}

	function getDBTransaction() {
		return $this->transaction;
	}

	function getFilePathManager() {

	}
}

?>
